<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta name="generator" content="Hugo 0.74.1" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>把flutter作为framework添加到已存在的iOS中 | caijinglong的博客</title>
    <meta property="og:title" content="把flutter作为framework添加到已存在的iOS中 - caijinglong的博客">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content="2019-06-16T11:17:43&#43;08:00">
        
        
    <meta property="article:modified_time" content="2019-06-16T11:17:43&#43;08:00">
        
    <meta name="Keywords" content="golang,go语言,flutter,caijinglong,java,android,博客,项目管理,python,软件架构,公众号,小程序">
    <meta name="description" content="把flutter作为framework添加到已存在的iOS中">
        
    <meta name="author" content="caijinglong">
    <meta property="og:url" content="http://www.kikt.top/posts/flutter/exists/add-flutter-to-ios/">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" href="/css/normalize.css">
    
        <link rel="stylesheet" href="/css/prism.css">
    
    <link rel="stylesheet" href="/css/style.css">
    <script type="text/javascript" src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

    

   
    <script>
        (function(){
            var bp = document.createElement('script');
            var curProtocol = window.location.protocol.split(':')[0];
            if (curProtocol === 'https') {
                bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
            }
            else {
                bp.src = 'http://push.zhanzhang.baidu.com/push.js';
            }
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(bp, s);
        })();
    </script>

    
    
</head>

<body>
<header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="http://www.kikt.top">
                        caijinglong的博客
                    </a>
                
                <p class="description">Android/Flutter开发者，对于golang/python/ios/java 均有所了解</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="" href="http://www.kikt.top">首页</a>
                    
                    <a  href="http://www.kikt.top/archives/" title="归档">归档</a>
                    
                    <a  href="http://www.kikt.top/contact/" title="接单">接单</a>
                    
                    <a  href="http://www.kikt.top/about/" title="关于">关于</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>


<div id="body">
    <div class="container">
        <div class="col-group">

            <div class="col-8" id="main">
                <div class="res-cons">
                    <article class="post">
                        <header>
                            <h1 class="post-title">把flutter作为framework添加到已存在的iOS中</h1>
                        </header>
                        <date class="post-meta meta-date">
                            2019年6月16日
                        </date>
                        
                        <div class="post-meta meta-category">
                            |
                            
                                <a href="http://www.kikt.top/categories/flutter">flutter</a>
                            
                                <a href="http://www.kikt.top/categories/ios">ios</a>
                            
                        </div>
                        
                        
                        <div class="post-meta">
                            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span> 阅读</span></span>
                        </div>
                        
                        <div class="post-content">
                            <p>之前写了一篇关于如何将 flutter 直接打包成 android aar 的文章, 本篇写一写如何将 flutter 打包成 framework 以便于直接让没有 flutter 环境的 iOS 开发者使用, 因为国内很多项目都有这样的要求</p>
<p>本篇并不会做完全的工程集成化, 只是做一下如何将 flutter 的 framework 打出来, 并且置入到 iOS 原生工程中, 因为各项目一定户会有自己的特殊性, 不可能完全一样</p>
<p>本篇打包脚本部分参考了 <a href="https://www.jianshu.com/p/700bd7d2122b">https://www.jianshu.com/p/700bd7d2122b</a> 的内容,但是又有一些针对 flutter 版本的变化和 flutter type 不同的情况进行的修改, 不观看连接中的内容并不会影响观看</p>
<ul>
<li><a href="#%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83">开发环境</a></li>
<li><a href="#%E5%88%9B%E5%BB%BA%E5%87%A0%E4%B8%AA%E5%B7%A5%E7%A8%8B">创建几个工程</a>
<ul>
<li><a href="#iOS-%E5%8E%9F%E7%94%9F%E5%B7%A5%E7%A8%8B">iOS 原生工程</a></li>
<li><a href="#Flutter-%E5%B7%A5%E7%A8%8B">Flutter 工程</a></li>
</ul>
</li>
<li><a href="#%E5%88%9B%E5%BB%BA%E8%84%9A%E6%9C%AC">创建脚本</a>
<ul>
<li><a href="#%E8%A7%82%E5%AF%9F%E7%BB%93%E6%9E%84">观察结构</a></li>
</ul>
</li>
<li><a href="#%E5%85%B3%E8%81%94%E5%BA%93%E6%96%87%E4%BB%B6%E5%92%8C%E5%B7%A5%E7%A8%8B">关联库文件和工程</a>
<ul>
<li><a href="#%E4%BD%BF%E7%94%A8-cocoapod-%E7%AE%A1%E7%90%86%E5%8E%9F%E7%94%9F%E5%B7%A5%E7%A8%8B">使用 cocoapod 管理原生工程</a></li>
<li><a href="#%E5%B0%86-framework-%E4%BD%9C%E4%B8%BA%E4%B8%80%E4%B8%AA-pod-%E5%BA%93">将 framework 作为一个 pod 库</a></li>
<li><a href="#%E5%9C%A8%E5%8E%9F%E7%94%9F%E9%A1%B9%E7%9B%AE%E4%B8%AD%E5%BC%95%E7%94%A8%E8%BF%99%E4%B8%AA%E5%BA%93">在原生项目中引用这个库</a></li>
</ul>
</li>
<li><a href="#%E4%BC%98%E5%8C%96%E8%84%9A%E6%9C%AC">优化脚本</a>
<ul>
<li><a href="#%E4%BC%98%E5%8C%96-podspec-%E6%96%87%E4%BB%B6">优化 podspec 文件</a></li>
<li><a href="#%E4%BC%98%E5%8C%96-shell-%E8%84%9A%E6%9C%AC">优化 shell 脚本</a>
<ul>
<li><a href="#%E9%AA%8C%E8%AF%81%E4%B8%8B%E5%88%AB%E7%9A%84%E6%8F%92%E4%BB%B6">验证下别的插件</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#%E6%80%BB%E7%BB%93">总结</a>
<ul>
<li><a href="#%E6%89%93%E5%8C%85%E7%9A%84%E4%BD%BF%E7%94%A8%E6%80%BB%E7%BB%93">打包的使用总结</a></li>
</ul>
</li>
<li><a href="#%E5%90%8E%E8%AE%B0">后记</a></li>
</ul>
<h2 id="开发环境">开发环境</h2>
<p>MacOS<br>
XCode 10<br>
git<br>
flutter 及 flutter 的相关工具链<br>
cocoapods</p>
<h2 id="创建几个工程">创建几个工程</h2>
<h3 id="ios-原生工程">iOS 原生工程</h3>
<p>使用 xcode 创建
<img src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&amp;path=%2F20190616112543.png&amp;versionDescriptor%5BversionOptions%5D=0&amp;versionDescriptor%5BversionType%5D=0&amp;resolveLfs=true&amp;%24format=octetStream&amp;api-version=5.0" alt="img"></p>
<p><img src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&amp;path=%2F20190616112618.png&amp;versionDescriptor%5BversionOptions%5D=0&amp;versionDescriptor%5BversionType%5D=0&amp;resolveLfs=true&amp;%24format=octetStream&amp;api-version=5.0" alt="img"></p>
<p>这个原生工程就是模拟你的原有工程</p>
<h3 id="flutter-工程">Flutter 工程</h3>
<p>这里我只使用 flutter module 的方式, 如果你 flutter 是 app 的方式创建的,则打包脚本的内容需要根据应用结构有所调整</p>
<p><code>$ flutter create -t module flutter_module_for_ios</code></p>
<p>这次直接在里面添加一个带有原生功能的插件, 和 android 篇相同依然选择 <a href="https://pub.dev/packages/shared_preferences#-installing-tab-">shared_preferences</a> 那个插件</p>
<p>修改 pubspec.yaml:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#66d9ef">dependencies</span>:
  <span style="color:#66d9ef">shared_preferences</span>: ^<span style="color:#ae81ff">0.5.3+1</span>
</code></pre></div><h2 id="创建脚本">创建脚本</h2>
<h3 id="观察结构">观察结构</h3>
<p>打包 iOS,然后观察 build 文件夹</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">flutter packages get
flutter build ios --release --no-codesign
</code></pre></div><div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">tree build/ios/Release-iphoneos
build/ios/Release-iphoneos
├── FlutterPluginRegistrant
│   └── libFlutterPluginRegistrant.a
├── Runner.app
│   ├── AppIcon20x20@2x.png
│   ├── AppIcon20x20@2x~ipad.png
│   ├── AppIcon20x20@3x.png
│   ├── AppIcon20x20~ipad.png
│   ├── AppIcon29x29.png
│   ├── AppIcon29x29@2x.png
│   ├── AppIcon29x29@2x~ipad.png
│   ├── AppIcon29x29@3x.png
│   ├── AppIcon29x29~ipad.png
│   ├── AppIcon40x40@2x.png
│   ├── AppIcon40x40@2x~ipad.png
│   ├── AppIcon40x40@3x.png
│   ├── AppIcon40x40~ipad.png
│   ├── AppIcon60x60@2x.png
│   ├── AppIcon60x60@3x.png
│   ├── AppIcon76x76@2x~ipad.png
│   ├── AppIcon76x76~ipad.png
│   ├── AppIcon83.5x83.5@2x~ipad.png
│   ├── Assets.car
│   ├── Base.lproj
│   │   ├── LaunchScreen.storyboardc
│   │   │   ├── 01J-lp-oVM-view-Ze5-6b-2t3.nib
│   │   │   ├── Info.plist
│   │   │   └── UIViewController-01J-lp-oVM.nib
│   │   └── Main.storyboardc
│   │       ├── BYZ-38-t0r-view-8bC-Xf-vdC.nib
│   │       ├── Info.plist
│   │       └── UIViewController-BYZ-38-t0r.nib
│   ├── Debug.xcconfig
│   ├── Flutter.xcconfig
│   ├── Frameworks
│   │   ├── App.framework
│   │   │   ├── App
│   │   │   ├── Info.plist
│   │   │   └── flutter_assets
│   │   │       ├── AssetManifest.json
│   │   │       ├── FontManifest.json
│   │   │       ├── LICENSE
│   │   │       ├── fonts
│   │   │       │   └── MaterialIcons-Regular.ttf
│   │   │       └── packages
│   │   │           └── cupertino_icons
│   │   │               └── assets
│   │   │                   └── CupertinoIcons.ttf
│   │   └── Flutter.framework
│   │       ├── Flutter
│   │       ├── Info.plist
│   │       └── icudtl.dat
│   ├── Info.plist
│   ├── PkgInfo
│   ├── Release.xcconfig
│   └── Runner
├── Runner.app.dSYM
│   └── Contents
│       ├── Info.plist
│       └── Resources
│           └── DWARF
│               └── Runner
├── libPods-Runner.a
└── shared_preferences
    └── libshared_preferences.a

<span style="color:#ae81ff">18</span> directories, <span style="color:#ae81ff">46</span> files
</code></pre></div><p>发现打包出来的是.a 文件, 这里我们需要修改一下 ios 目录下的文件, 以便于打包出来 framework 文件, 因为 framework 是 apple 提供的一种打包方案, 直接将所有需要的资源包括头文件,库文件都聚集到了一起,方便引用, 而.a 文件就不一样了, 还需要包含对应的头文件</p>
<p>修改.ios 下的 podfile</p>
<p>在第一行添加这个</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ruby" data-lang="ruby">use_frameworks!
</code></pre></div><p>然后先清除一下刚刚打包的内容 <code>$ flutter clean</code></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">flutter build ios --release --no-codesign
</code></pre></div><pre><code class="language-tree" data-lang="tree">tree build/ios/Release-iphoneos
build/ios/Release-iphoneos
├── FlutterPluginRegistrant
│   ├── FlutterPluginRegistrant.framework
│   │   ├── FlutterPluginRegistrant
│   │   ├── Headers
│   │   │   ├── FlutterPluginRegistrant-umbrella.h
│   │   │   └── GeneratedPluginRegistrant.h
│   │   ├── Info.plist
│   │   └── Modules
│   │       └── module.modulemap
│   └── FlutterPluginRegistrant.framework.dSYM
│       └── Contents
│           ├── Info.plist
│           └── Resources
│               └── DWARF
│                   └── FlutterPluginRegistrant
├── Pods_Runner.framework
│   ├── Headers
│   │   └── Pods-Runner-umbrella.h
│   ├── Info.plist
│   ├── Modules
│   │   └── module.modulemap
│   └── Pods_Runner
├── Runner.app
│   ├── AppIcon20x20@2x.png
│   ├── AppIcon20x20@2x~ipad.png
│   ├── AppIcon20x20@3x.png
│   ├── AppIcon20x20~ipad.png
│   ├── AppIcon29x29.png
│   ├── AppIcon29x29@2x.png
│   ├── AppIcon29x29@2x~ipad.png
│   ├── AppIcon29x29@3x.png
│   ├── AppIcon29x29~ipad.png
│   ├── AppIcon40x40@2x.png
│   ├── AppIcon40x40@2x~ipad.png
│   ├── AppIcon40x40@3x.png
│   ├── AppIcon40x40~ipad.png
│   ├── AppIcon60x60@2x.png
│   ├── AppIcon60x60@3x.png
│   ├── AppIcon76x76@2x~ipad.png
│   ├── AppIcon76x76~ipad.png
│   ├── AppIcon83.5x83.5@2x~ipad.png
│   ├── Assets.car
│   ├── Base.lproj
│   │   ├── LaunchScreen.storyboardc
│   │   │   ├── 01J-lp-oVM-view-Ze5-6b-2t3.nib
│   │   │   ├── Info.plist
│   │   │   └── UIViewController-01J-lp-oVM.nib
│   │   └── Main.storyboardc
│   │       ├── BYZ-38-t0r-view-8bC-Xf-vdC.nib
│   │       ├── Info.plist
│   │       └── UIViewController-BYZ-38-t0r.nib
│   ├── Debug.xcconfig
│   ├── Flutter.xcconfig
│   ├── Frameworks
│   │   ├── App.framework
│   │   │   ├── App
│   │   │   ├── Info.plist
│   │   │   └── flutter_assets
│   │   │       ├── AssetManifest.json
│   │   │       ├── FontManifest.json
│   │   │       ├── LICENSE
│   │   │       ├── fonts
│   │   │       │   └── MaterialIcons-Regular.ttf
│   │   │       └── packages
│   │   │           └── cupertino_icons
│   │   │               └── assets
│   │   │                   └── CupertinoIcons.ttf
│   │   ├── Flutter.framework
│   │   │   ├── Flutter
│   │   │   ├── Info.plist
│   │   │   └── icudtl.dat
│   │   ├── FlutterPluginRegistrant.framework
│   │   │   ├── FlutterPluginRegistrant
│   │   │   └── Info.plist
│   │   └── shared_preferences.framework
│   │       ├── Info.plist
│   │       └── shared_preferences
│   ├── Info.plist
│   ├── PkgInfo
│   ├── Release.xcconfig
│   └── Runner
├── Runner.app.dSYM
│   └── Contents
│       ├── Info.plist
│       └── Resources
│           └── DWARF
│               └── Runner
└── shared_preferences
    ├── shared_preferences.framework
    │   ├── Headers
    │   │   ├── SharedPreferencesPlugin.h
    │   │   └── shared_preferences-umbrella.h
    │   ├── Info.plist
    │   ├── Modules
    │   │   └── module.modulemap
    │   └── shared_preferences
    └── shared_preferences.framework.dSYM
        └── Contents
            ├── Info.plist
            └── Resources
                └── DWARF
                    └── shared_preferences

37 directories, 65 files
</code></pre><p>Runner.app 这个熟悉的名字下虽然看似包含所有的 framework,但是仔细观察, 这些 framework 内不包含头文件, 所以其实是用不了的</p>
<p>可以使用的是如图所示的几个</p>
<p><img src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&amp;path=%2F20190616114446.png&amp;versionDescriptor%5BversionOptions%5D=0&amp;versionDescriptor%5BversionType%5D=0&amp;resolveLfs=true&amp;%24format=octetStream&amp;api-version=5.0" alt="img"></p>
<p>根据上面的 tree 图可以看到,其中包含了全部的库文件, 但除此以外,还需要两个库:</p>
<ol>
<li>App.framework: 这个包含了 flutter 的资源</li>
<li>Flutter.framework: 这个是 Flutter 的 engine 运行库, 每个 flutter 应用必然有的东西</li>
</ol>
<p>这两个东西需要从.ios 中找到</p>
<ol>
<li>App.framework: .ios/Flutter/App.framework</li>
<li>Flutter.framework: .ios/Flutter/engine/Flutter.framework</li>
</ol>
<p>这样就集齐了所有的库文件, 问题是, 这样是手动做的, 我们需要一个自动化的方案把重复的工作都完成</p>
<p>所以我根据开头的文章内的脚本编写了一个脚本:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> -z $out <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
    out<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;ios_frameworks&#39;</span>
<span style="color:#66d9ef">fi</span>

echo <span style="color:#e6db74">&#34;准备输出所有文件到目录: </span>$out<span style="color:#e6db74">&#34;</span>

find . -d -name build | xargs rm -rf
flutter clean
rm -rf $out
rm -rf build

flutter packages get
flutter build ios --release --no-codesign

mkdir $out

cp -r build/ios/Release-iphoneos/*/*.framework $out
cp -r .ios/Flutter/App.framework $out
cp -r .ios/Flutter/engine/Flutter.framework $out
</code></pre></div><p>接着可以通过<code>sh build_ios.sh</code> 来自动打包,并且将所有文件复制到 ios_frameword 目录下, 嗯 这个目录可以通过
<code>out=ios_out sh build_ios.sh</code>来改变</p>
<h2 id="关联库文件和工程">关联库文件和工程</h2>
<p>原生工程的管理方式有很多种, 比如只使用 xcode 来管理</p>
<p>cocoapod(支持 oc 和 swift)</p>
<p>单独针对 swift 还有 Carthage, Swift Package Manager</p>
<p>当然这里我还是用 cocoapod 的方案, 其他的方案请自行研究</p>
<h3 id="使用-cocoapod-管理原生工程">使用 cocoapod 管理原生工程</h3>
<p>为原生工程添加一个 Podfile</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">cd top.kikt.existsapp
touch Podfile
code Podfile <span style="color:#75715e"># 这一步是用 vscode 打开 你也可以用 vim 或其他任何文本编辑器</span>
</code></pre></div><p>修改 Podfile</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rb" data-lang="rb">platform <span style="color:#e6db74">:ios</span>, <span style="color:#e6db74">&#39;8.0&#39;</span>
use_frameworks!

target <span style="color:#e6db74">&#39;top.kikt.existsapp&#39;</span> <span style="color:#66d9ef">do</span>

<span style="color:#66d9ef">end</span>
</code></pre></div><p>然后继续在命令行里 <code>$ pod install</code></p>
<p>如果没有报错, 则说明原生项目现在已经被 pod 管理了</p>
<h3 id="将-framework-作为一个-pod-库">将 framework 作为一个 pod 库</h3>
<p>因为找遍了 podfile 的相关文档, 没有找到可以直接引用 framework 的方式</p>
<p>所以需要一个 pod 库作为&quot;中转&rdquo;</p>
<p>新建一个库 <code>$ pod lib create flutter-lib</code>, 然后按顺序回答问题, 这目录根据你自己的实际情况来</p>
<p>我的是和 iOS 原生同级目录</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ pod lib create flutter-lib
Cloning <span style="color:#e6db74">`</span>https://github.com/CocoaPods/pod-template.git<span style="color:#e6db74">`</span> into <span style="color:#e6db74">`</span>flutter-lib<span style="color:#e6db74">`</span>.
Configuring flutter-lib template.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide:
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 <span style="color:#f92672">(</span> hold cmd and double click links to open in a browser. <span style="color:#f92672">)</span>


What platform <span style="color:#66d9ef">do</span> you want to use?? <span style="color:#f92672">[</span> iOS / macOS <span style="color:#f92672">]</span>
 &gt;
ios
What language <span style="color:#66d9ef">do</span> you want to use?? <span style="color:#f92672">[</span> Swift / ObjC <span style="color:#f92672">]</span>
 &gt; objc

Would you like to include a demo application with your library? <span style="color:#f92672">[</span> Yes / No <span style="color:#f92672">]</span>
 &gt; no

Which testing frameworks will you use? <span style="color:#f92672">[</span> Specta / Kiwi / None <span style="color:#f92672">]</span>
 &gt; none

Would you like to <span style="color:#66d9ef">do</span> view based testing? <span style="color:#f92672">[</span> Yes / No <span style="color:#f92672">]</span>
 &gt; no

What is your class prefix?
 &gt;

You need to provide an answer.
What is your class prefix?
 &gt; FFF

Running pod install on your new library.

Analyzing dependencies
Fetching podspec <span style="color:#66d9ef">for</span> <span style="color:#e6db74">`</span>flutter-lib<span style="color:#e6db74">`</span> from <span style="color:#e6db74">`</span>../<span style="color:#e6db74">`</span>
Downloading dependencies
Installing flutter-lib <span style="color:#f92672">(</span>0.1.0<span style="color:#f92672">)</span>
Generating Pods project
Integrating client project

<span style="color:#f92672">[</span>!<span style="color:#f92672">]</span> Please close any current Xcode sessions and use <span style="color:#e6db74">`</span>flutter-lib.xcworkspace<span style="color:#e6db74">`</span> <span style="color:#66d9ef">for</span> this project from now on.
Sending stats
Pod installation complete! There is <span style="color:#ae81ff">1</span> dependency from the Podfile and <span style="color:#ae81ff">1</span> total pod installed.

<span style="color:#f92672">[</span>!<span style="color:#f92672">]</span> Automatically assigning platform <span style="color:#e6db74">`</span>ios<span style="color:#e6db74">`</span> with version <span style="color:#e6db74">`</span>9.3<span style="color:#e6db74">`</span> on target <span style="color:#e6db74">`</span>flutter-lib_Tests<span style="color:#e6db74">`</span> because no platform was specified. Please specify a platform <span style="color:#66d9ef">for</span> this target in your Podfile. See <span style="color:#e6db74">`</span>https://guides.cocoapods.org/syntax/podfile.html#platform<span style="color:#e6db74">`</span>.

 Ace! you<span style="color:#e6db74">&#39;re ready to go!
</span><span style="color:#e6db74"> We will start you off by opening your project in Xcode
</span><span style="color:#e6db74">  open &#39;</span>flutter-lib/Example/flutter-lib.xcworkspace<span style="color:#960050;background-color:#1e0010">&#39;</span>

To learn more about the template see <span style="color:#e6db74">`</span>https://github.com/CocoaPods/pod-template.git<span style="color:#e6db74">`</span>.
To learn more about creating a new pod, see <span style="color:#e6db74">`</span>https://guides.cocoapods.org/making/making-a-cocoapod<span style="color:#e6db74">`</span>.
</code></pre></div><p>创建完成后, 修改 flutter-lib.podspec 文件</p>
<p>这里需要先把刚刚的 framework 复制到项目中</p>
<p>默认有一堆注释都可以删掉</p>
<p>然后添加这么一行</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rb" data-lang="rb">s<span style="color:#f92672">.</span>ios<span style="color:#f92672">.</span>vendored_frameworks <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;ios_frameworks/App.framework&#39;</span>, <span style="color:#e6db74">&#39;ios_frameworks/Flutter.framework&#39;</span>, <span style="color:#e6db74">&#39;ios_frameworks/FlutterPluginRegistrant.framework&#39;</span>, <span style="color:#e6db74">&#39;ios_frameworks/shared_preferences.framework&#39;</span>
</code></pre></div><p>这个方案是临时的, 后面肯定会写成动态查找的方案, 不可能有一个库写一次</p>
<p>现在我的 podspec 文件是这样的</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rb" data-lang="rb"><span style="color:#66d9ef">Pod</span><span style="color:#f92672">::</span><span style="color:#66d9ef">Spec</span><span style="color:#f92672">.</span>new <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>s<span style="color:#f92672">|</span>
  s<span style="color:#f92672">.</span>name             <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flutter-lib&#39;</span>
  s<span style="color:#f92672">.</span>version          <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;0.1.0&#39;</span>
  s<span style="color:#f92672">.</span>summary          <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;A short description of flutter-lib.&#39;</span>
  s<span style="color:#f92672">.</span>description      <span style="color:#f92672">=</span> <span style="color:#e6db74">&lt;&lt;-DESC
</span><span style="color:#e6db74"></span><span style="color:#e6db74">TODO</span>: <span style="color:#66d9ef">Add</span> long description of the pod here<span style="color:#f92672">.</span>
                       <span style="color:#66d9ef">DESC</span>

  s<span style="color:#f92672">.</span>homepage         <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;https://github.com/cjl_spy@163.com/flutter-lib&#39;</span>
  s<span style="color:#f92672">.</span>license          <span style="color:#f92672">=</span> { <span style="color:#e6db74">:type</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;MIT&#39;</span>, <span style="color:#e6db74">:file</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;LICENSE&#39;</span> }
  s<span style="color:#f92672">.</span>author           <span style="color:#f92672">=</span> { <span style="color:#e6db74">&#39;cjl_spy@163.com&#39;</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;cjl_spy@163.com&#39;</span> }
  s<span style="color:#f92672">.</span>source           <span style="color:#f92672">=</span> { <span style="color:#e6db74">:git</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;https://github.com/cjl_spy@163.com/flutter-lib.git&#39;</span>, <span style="color:#e6db74">:tag</span> <span style="color:#f92672">=&gt;</span> s<span style="color:#f92672">.</span>version<span style="color:#f92672">.</span>to_s }
  s<span style="color:#f92672">.</span>ios<span style="color:#f92672">.</span>deployment_target <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;8.0&#39;</span>
  s<span style="color:#f92672">.</span>static_framework <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>
  <span style="color:#75715e"># s.source_files = &#39;flutter-lib/Classes/**/*&#39;</span>
  s<span style="color:#f92672">.</span>ios<span style="color:#f92672">.</span>vendored_frameworks <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;ios_frameworks/App.framework&#39;</span>, <span style="color:#e6db74">&#39;ios_frameworks/Flutter.framework&#39;</span>, <span style="color:#e6db74">&#39;ios_frameworks/FlutterPluginRegistrant.framework&#39;</span>, <span style="color:#e6db74">&#39;ios_frameworks/shared_preferences.framework&#39;</span>
<span style="color:#66d9ef">end</span>
</code></pre></div><h3 id="在原生项目中引用这个库">在原生项目中引用这个库</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rb" data-lang="rb">platform <span style="color:#e6db74">:ios</span>, <span style="color:#e6db74">&#39;8.0&#39;</span>
use_frameworks!

target <span style="color:#e6db74">&#39;top.kikt.existsapp&#39;</span> <span style="color:#66d9ef">do</span>
   pod <span style="color:#e6db74">&#39;flutter-lib&#39;</span>, <span style="color:#e6db74">:path</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;../flutter-lib&#39;</span>
<span style="color:#66d9ef">end</span>
</code></pre></div><p>接着在原生项目中<code>$ pod install</code></p>
<p>运行项目可能会有两种错误:</p>
<p>信息包含什么 System 之类的, 这个是需要修改构建系统</p>
<p><img src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&amp;path=%2F20190616181824.png&amp;versionDescriptor%5BversionOptions%5D=0&amp;versionDescriptor%5BversionType%5D=0&amp;resolveLfs=true&amp;%24format=octetStream&amp;api-version=5.0" alt="img"></p>
<p>运行项目还可能会报一个 bitcode 的错误, 这里需要修改一个选项
<img src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&amp;path=%2F20190616134945.png&amp;versionDescriptor%5BversionOptions%5D=0&amp;versionDescriptor%5BversionType%5D=0&amp;resolveLfs=true&amp;%24format=octetStream&amp;api-version=5.0" alt="img">
将这里修改为 NO</p>
<p>我的项目目前为止能跑起来不报错了, 但是目前项目还没有启动 Flutter 的页面, 到这一步后我是按照 <a href="https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps#write-code-to-use-flutterviewcontroller-from-your-host-app">flutter 官方 wiki</a> 进行修改的</p>
<p>我给的例子仅有 oc 的,swift 的请自行参考 wiki</p>
<p>修改<code>AppDelegate.h</code></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-objc" data-lang="objc"><span style="color:#75715e">#import &lt;UIKit/UIKit.h&gt;
</span><span style="color:#75715e">#import &lt;Flutter/Flutter.h&gt;
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">@interface</span> <span style="color:#a6e22e">AppDelegate</span> : <span style="color:#a6e22e">FlutterAppDelegate</span>
<span style="color:#66d9ef">@property</span> (<span style="color:#66d9ef">nonatomic</span>,<span style="color:#66d9ef">strong</span>) FlutterEngine <span style="color:#f92672">*</span>flutterEngine;
<span style="color:#66d9ef">@end</span>
</code></pre></div><p><code>AppDelegate.m</code></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-objc" data-lang="objc"><span style="color:#75715e">#import &lt;FlutterPluginRegistrant/GeneratedPluginRegistrant.h&gt; </span><span style="color:#75715e">// Only if you have Flutter Plugins
</span><span style="color:#75715e"></span>
<span style="color:#75715e">#include</span> <span style="color:#75715e">&#34;AppDelegate.h&#34;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">@implementation</span> <span style="color:#a6e22e">AppDelegate</span>

<span style="color:#75715e">// This override can be omitted if you do not have any Flutter Plugins.
</span><span style="color:#75715e"></span>- (<span style="color:#66d9ef">BOOL</span>)<span style="color:#a6e22e">application:</span>(UIApplication <span style="color:#f92672">*</span>)application
    <span style="color:#a6e22e">didFinishLaunchingWithOptions:</span>(NSDictionary <span style="color:#f92672">*</span>)launchOptions {
  self.flutterEngine <span style="color:#f92672">=</span> [[FlutterEngine alloc] initWithName:<span style="color:#e6db74">@&#34;io.flutter&#34;</span> project:nil];
  [self.flutterEngine runWithEntrypoint:nil];
  [GeneratedPluginRegistrant registerWithRegistry:self.flutterEngine];
  <span style="color:#66d9ef">return</span> [super application:application didFinishLaunchingWithOptions:launchOptions];
}

<span style="color:#66d9ef">@end</span>
</code></pre></div><p>接着就是启动 Flutter 的事情了, 这个根据你业务逻辑自行实现, 核心代码是如下几行</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-objc" data-lang="objc"><span style="color:#75715e">#import &lt;Flutter/Flutter.h&gt;
</span><span style="color:#75715e">#import &#34;AppDelegate.h&#34;
</span><span style="color:#75715e">#import &#34;ViewController.h&#34;
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">@implementation</span> <span style="color:#a6e22e">ViewController</span>
- (<span style="color:#66d9ef">void</span>)<span style="color:#a6e22e">viewDidLoad</span> {
    [super viewDidLoad];
    UIButton <span style="color:#f92672">*</span>button <span style="color:#f92672">=</span> [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self
               action:<span style="color:#66d9ef">@selector</span>(handleButtonAction)
     forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:<span style="color:#e6db74">@&#34;Press me&#34;</span> forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor blueColor]];
    button.frame <span style="color:#f92672">=</span> CGRectMake(<span style="color:#ae81ff">80.0</span>, <span style="color:#ae81ff">210.0</span>, <span style="color:#ae81ff">160.0</span>, <span style="color:#ae81ff">40.0</span>);
    [self.view addSubview:button];
}

- (<span style="color:#66d9ef">void</span>)<span style="color:#a6e22e">handleButtonAction</span> {
    FlutterEngine <span style="color:#f92672">*</span>flutterEngine <span style="color:#f92672">=</span> [(AppDelegate <span style="color:#f92672">*</span>)[[UIApplication sharedApplication] delegate] flutterEngine];
    FlutterViewController <span style="color:#f92672">*</span>flutterViewController <span style="color:#f92672">=</span> [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil];
    [self presentViewController:flutterViewController animated:false completion:nil];
}
<span style="color:#66d9ef">@end</span>
</code></pre></div><h2 id="优化脚本">优化脚本</h2>
<h3 id="优化-podspec-文件">优化 podspec 文件</h3>
<p>这一步的目的是, 遍历文件夹, 不再单独的每个引用 framework 文件</p>
<p>podspec 使用的是 ruby 语法, 也就是说本身就支持编程, 这时候如果再用 shell 或者 dart 就有点增加复杂度了</p>
<p>如果不了解 ruby 语法, 你也可以用自己的方法解决(shell,python,dart 什么都随你), 我也是边写边看的 ruby 语法, 按照如下方式修改</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-rb" data-lang="rb"><span style="color:#66d9ef">Pod</span><span style="color:#f92672">::</span><span style="color:#66d9ef">Spec</span><span style="color:#f92672">.</span>new <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>s<span style="color:#f92672">|</span>
  s<span style="color:#f92672">.</span>name             <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;flutter-lib&#39;</span>
  s<span style="color:#f92672">.</span>version          <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;0.1.0&#39;</span>
  s<span style="color:#f92672">.</span>summary          <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;A short description of flutter-lib.&#39;</span>
  s<span style="color:#f92672">.</span>description      <span style="color:#f92672">=</span> <span style="color:#e6db74">&lt;&lt;-DESC
</span><span style="color:#e6db74"></span><span style="color:#e6db74">TODO</span>: <span style="color:#66d9ef">Add</span> long description of the pod here<span style="color:#f92672">.</span>
                       <span style="color:#66d9ef">DESC</span>

  s<span style="color:#f92672">.</span>homepage         <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;https://github.com/cjl_spy@163.com/flutter-lib&#39;</span>
  s<span style="color:#f92672">.</span>license          <span style="color:#f92672">=</span> { <span style="color:#e6db74">:type</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;MIT&#39;</span>, <span style="color:#e6db74">:file</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;LICENSE&#39;</span> }
  s<span style="color:#f92672">.</span>author           <span style="color:#f92672">=</span> { <span style="color:#e6db74">&#39;cjl_spy@163.com&#39;</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;cjl_spy@163.com&#39;</span> }
  s<span style="color:#f92672">.</span>source           <span style="color:#f92672">=</span> { <span style="color:#e6db74">:git</span> <span style="color:#f92672">=&gt;</span> <span style="color:#e6db74">&#39;https://github.com/cjl_spy@163.com/flutter-lib.git&#39;</span>, <span style="color:#e6db74">:tag</span> <span style="color:#f92672">=&gt;</span> s<span style="color:#f92672">.</span>version<span style="color:#f92672">.</span>to_s }
  s<span style="color:#f92672">.</span>ios<span style="color:#f92672">.</span>deployment_target <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;8.0&#39;</span>
  s<span style="color:#f92672">.</span>static_framework <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>
  <span style="color:#75715e"># s.source_files = &#39;flutter-lib/Classes/**/*&#39;</span>
  p <span style="color:#f92672">=</span> <span style="color:#66d9ef">Dir</span><span style="color:#f92672">::</span>open(<span style="color:#e6db74">&#34;ios_frameworks&#34;</span>)
  arr <span style="color:#f92672">=</span> Array<span style="color:#f92672">.</span>new
  p<span style="color:#f92672">.</span>each <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>f<span style="color:#f92672">|</span>
    <span style="color:#66d9ef">if</span> f <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;.&#39;</span> <span style="color:#f92672">||</span> f <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;..&#39;</span>
    <span style="color:#66d9ef">else</span>
        arr<span style="color:#f92672">.</span>push(<span style="color:#e6db74">&#39;ios_frameworks/&#39;</span><span style="color:#f92672">+</span>f)
    <span style="color:#66d9ef">end</span>
  <span style="color:#66d9ef">end</span>

  s<span style="color:#f92672">.</span>ios<span style="color:#f92672">.</span>vendored_frameworks <span style="color:#f92672">=</span> arr
<span style="color:#66d9ef">end</span>
</code></pre></div><p>然后执行 pod install</p>
<h3 id="优化-shell-脚本">优化 shell 脚本</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> -z $out <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
    out<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;ios_frameworks&#39;</span>
<span style="color:#66d9ef">fi</span>

echo <span style="color:#e6db74">&#34;准备输出所有文件到目录: </span>$out<span style="color:#e6db74">&#34;</span>

find . -d -name build | xargs rm -rf
flutter clean
rm -rf $out
rm -rf build

flutter packages get
flutter build ios --release --no-codesign

mkdir $out

cp -r build/ios/Release-iphoneos/*/*.framework $out
cp -r .ios/Flutter/App.framework $out
cp -r .ios/Flutter/engine/Flutter.framework $out

cp -r $out ../flutter-lib/ios_frameworks <span style="color:#75715e"># 添加这步</span>
</code></pre></div><h4 id="验证下别的插件">验证下别的插件</h4>
<p>添加插件到 pubspec.yaml</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#66d9ef">dependencies</span>:
  <span style="color:#66d9ef">path_provider</span>: ^<span style="color:#ae81ff">1.1.0</span>
</code></pre></div><p><code>$ flutter pub get</code></p>
<p>这里有个小坑,当添加了 pubspec 插件后, flutter/.ios/Podfile 的内容会被恢复成默认状态</p>
<p>所以需要再修改一下 shell 脚本:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> -z $out <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
    out<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;ios_frameworks&#39;</span>
<span style="color:#66d9ef">fi</span>

echo <span style="color:#e6db74">&#34;准备输出所有文件到目录: </span>$out<span style="color:#e6db74">&#34;</span>

echo <span style="color:#e6db74">&#34;清除所有已编译文件&#34;</span>
find . -d -name build | xargs rm -rf
flutter clean
rm -rf $out
rm -rf build

flutter packages get

addFlag<span style="color:#f92672">(){</span>
    cat .ios/Podfile &gt; tmp1.txt
    echo <span style="color:#e6db74">&#34;use_frameworks!&#34;</span> &gt;&gt; tmp2.txt
    cat tmp1.txt &gt;&gt; tmp2.txt
    cat tmp2.txt &gt; .ios/Podfile
    rm tmp1.txt tmp2.txt
<span style="color:#f92672">}</span>

echo <span style="color:#e6db74">&#34;检查 .ios/Podfile文件状态&#34;</span>
a<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>cat .ios/Podfile<span style="color:#66d9ef">)</span>
<span style="color:#66d9ef">if</span> <span style="color:#f92672">[[</span> $a <span style="color:#f92672">==</span> use* <span style="color:#f92672">]]</span>; <span style="color:#66d9ef">then</span>
    echo <span style="color:#e6db74">&#39;已经添加use_frameworks, 不再添加&#39;</span>
<span style="color:#66d9ef">else</span>
    echo <span style="color:#e6db74">&#39;未添加use_frameworks,准备添加&#39;</span>
    addFlag
    echo <span style="color:#e6db74">&#34;添加use_frameworks 完成&#34;</span>
<span style="color:#66d9ef">fi</span>

echo <span style="color:#e6db74">&#34;编译flutter&#34;</span>
flutter build ios --release --no-codesign

echo <span style="color:#e6db74">&#34;编译flutter完成&#34;</span>
mkdir $out

cp -r build/ios/Release-iphoneos/*/*.framework $out
cp -r .ios/Flutter/App.framework $out
cp -r .ios/Flutter/engine/Flutter.framework $out

echo <span style="color:#e6db74">&#34;复制framework库到临时文件夹: </span>$out<span style="color:#e6db74">&#34;</span>

libpath<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;../flutter-lib&#39;</span>

rm -rf <span style="color:#e6db74">&#34;</span>$libpath<span style="color:#e6db74">/ios_frameworks&#34;</span>
mkdir $libpath
cp -r $out $libpath

echo <span style="color:#e6db74">&#34;复制库文件到: </span>$libpath<span style="color:#e6db74">&#34;</span>
</code></pre></div><p>顺便润色了一下,加了一点日志</p>
<p>运行下项目, 跑了一下, 果然没有问题了</p>
<p><del>这里有一个插曲请注意,我脚本里用了 gsed 命令,这个工具是 GNU-sed 的缩写, 因为 mac 的 sed 命令有一些问题比较难用</del><br>
<del>请使用<code>$ brew install gnu-sed</code>安装一下, 否则这个命令可能失败</del></p>
<p>备注: 因为有反馈, gsed 在不同的 mac 上会出现把文本变成一行的问题, 现在采用另一种方案,不再需要 gsed</p>
<h2 id="总结">总结</h2>
<p>建议: 请将 flutter,原生和 flutter 的 framework 所在的 pod 库作为 3 个单独的库,便于管理(有 pod 的私服请按照自己的方案实现 framework 的共享)</p>
<p>然后脚本中的目录什么的需要根据你的实际情况进行调整</p>
<h3 id="打包的使用总结">打包的使用总结</h3>
<p>flutter 方:</p>
<ol>
<li>创建一个 pod 库</li>
<li>使用脚本打包并把所有的文件复制到 pod 库内</li>
<li>git commit + push</li>
</ol>
<p>ios 方:</p>
<ol>
<li>git pull</li>
<li>pod install</li>
<li>run</li>
</ol>
<h2 id="后记">后记</h2>
<p>到目前为止, iOS 也算是完成了加入到已有工程, 原生方只使用 pod+git 理论上就达到了可以不用 flutter 依然可运行的目的</p>
<p>仓库看这里: <a href="https://github.com/CaiJingLong/add_flutter_to_exists_ios_example">https://github.com/CaiJingLong/add_flutter_to_exists_ios_example</a></p>
<p>以上</p>

                        </div>

                        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/posts/flutter/dart/generators/">dart中的生成器函数</a></li>
        
        <li><a href="/posts/flutter/exists/android/">在原 Android 工程的基础上构建一个flutter工程</a></li>
        
        <li><a href="/posts/flutter/exists/android-as-aar-to-maven/">把flutter项目作为aar添加到已有的Android工程上</a></li>
        
        <li><a href="/posts/flutter/desktop/flutter-desktop-2/">Flutter Desktop Mac版(二) 插件初探</a></li>
        
        <li><a href="/posts/flutter/desktop/flutter-desktop-1/">Flutter Desktop Mac版(一) 初探</a></li>
        
    </ul>
</div>


                        <div class="post-meta meta-tags">
                            
                            <ul class="clearfix">
                                
                                <li><a href="http://www.kikt.top/tags/flutter">flutter</a></li>
                                
                                <li><a href="http://www.kikt.top/tags/ios">ios</a></li>
                                
                                <li><a href="http://www.kikt.top/tags/exists">exists</a></li>
                                
                                <li><a href="http://www.kikt.top/tags/framework">framework</a></li>
                                
                            </ul>
                            
                        </div>
                    </article>
                    
    

    
    
    <div class="post bg-white">
      <script src="https://utteranc.es/client.js"
            repo= "caijinglong/kikt-blog-comment"
            issue-term="pathname"
            theme="github-light"
            crossorigin="anonymous"
            async>
      </script>
    </div>
    
                </div>
            </div>
            <div id="secondary">
    <section class="widget">
        <form id="search" action="//www.google.com/search" method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="http://www.kikt.top">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="http://www.kikt.top/posts/java/crack/crack1/" title="使用javassist,修改jar包方法实现">使用javassist,修改jar包方法实现</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/github/actions/create/" title="Github action 的开发到发布">Github action 的开发到发布</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/jenkins&#43;fastlane/" title="flutter Jenkins&#43;fastlane 自动化打测试包, 并上传蒲公英">flutter Jenkins&#43;fastlane 自动化打测试包, 并上传蒲公英</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/go/compile-for-android/" title="编译 go 源码为 android 动态库(so)">编译 go 源码为 android 动态库(so)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/focusnode-2/" title="Flutter FocusNode 焦点那点事-(二)">Flutter FocusNode 焦点那点事-(二)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/focusnode-1/" title="Flutter FocusNode 焦点那点事-(一)">Flutter FocusNode 焦点那点事-(一)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/server/caddy/cros_for_local_dev/" title="用 Caddy 解决 web 开发中本地跨域的问题">用 Caddy 解决 web 开发中本地跨域的问题</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/route/navigator-helper2/" title="Navigator Helper2">Navigator Helper2</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/grey-app/" title="flutter 怎么实现app整体灰度">flutter 怎么实现app整体灰度</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/plugin/flutter-sdk-import-aar/" title="Flutter 插件开发之引入aar到安卓部分 并使用本地maven">Flutter 插件开发之引入aar到安卓部分 并使用本地maven</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title">分类</h3>
<ul class="widget-list">
    
    <li>
        <a href="http://www.kikt.top/categories/android/">android(25)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/caddy/">caddy(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/dart/">dart(5)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/docker/">docker(3)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/flutter/">flutter(60)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/github/">github(3)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/go/">go(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/golang/">golang(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/iOS/">iOS(6)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/ios/">ios(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/java/">java(6)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/jetbrains/">jetbrains(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/other/">other(3)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/python/">python(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/server/">server(5)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/spring/">spring(3)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/tools/">tools(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/%E6%9D%82%E9%A1%B9/">杂项(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/%E6%B6%82%E9%B8%A6/">涂鸦(1)</a>
    </li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title">标签</h3>
<div class="tagcloud">
    
    <a href="http://www.kikt.top/tags/10/">10</a>
    
    <a href="http://www.kikt.top/tags/2.3/">2.3</a>
    
    <a href="http://www.kikt.top/tags/Clipboard/">Clipboard</a>
    
    <a href="http://www.kikt.top/tags/Javassist/">Javassist</a>
    
    <a href="http://www.kikt.top/tags/Migrate/">Migrate</a>
    
    <a href="http://www.kikt.top/tags/aar/">aar</a>
    
    <a href="http://www.kikt.top/tags/actions/">actions</a>
    
    <a href="http://www.kikt.top/tags/aidl/">aidl</a>
    
    <a href="http://www.kikt.top/tags/android/">android</a>
    
    <a href="http://www.kikt.top/tags/androidQ/">androidQ</a>
    
    <a href="http://www.kikt.top/tags/androidX/">androidX</a>
    
    <a href="http://www.kikt.top/tags/apk/">apk</a>
    
    <a href="http://www.kikt.top/tags/app/">app</a>
    
    <a href="http://www.kikt.top/tags/appcode/">appcode</a>
    
    <a href="http://www.kikt.top/tags/azure/">azure</a>
    
    <a href="http://www.kikt.top/tags/ble/">ble</a>
    
    <a href="http://www.kikt.top/tags/bottomsheet/">bottomsheet</a>
    
    <a href="http://www.kikt.top/tags/butterknife/">butterknife</a>
    
    <a href="http://www.kikt.top/tags/c/">c</a>
    
    <a href="http://www.kikt.top/tags/caddy/">caddy</a>
    
    <a href="http://www.kikt.top/tags/camera/">camera</a>
    
    <a href="http://www.kikt.top/tags/cameraX/">cameraX</a>
    
    <a href="http://www.kikt.top/tags/channel/">channel</a>
    
    <a href="http://www.kikt.top/tags/cocoapods/">cocoapods</a>
    
    <a href="http://www.kikt.top/tags/cupertino/">cupertino</a>
    
    <a href="http://www.kikt.top/tags/dart/">dart</a>
    
    <a href="http://www.kikt.top/tags/dart-2.6/">dart-2.6</a>
    
    <a href="http://www.kikt.top/tags/desktop/">desktop</a>
    
    <a href="http://www.kikt.top/tags/dialog/">dialog</a>
    
    <a href="http://www.kikt.top/tags/dmg/">dmg</a>
    
    <a href="http://www.kikt.top/tags/doc/">doc</a>
    
    <a href="http://www.kikt.top/tags/docker/">docker</a>
    
    <a href="http://www.kikt.top/tags/docker-compose/">docker-compose</a>
    
    <a href="http://www.kikt.top/tags/excel/">excel</a>
    
    <a href="http://www.kikt.top/tags/exists/">exists</a>
    
    <a href="http://www.kikt.top/tags/faq/">faq</a>
    
    <a href="http://www.kikt.top/tags/fastlane/">fastlane</a>
    
    <a href="http://www.kikt.top/tags/ffi/">ffi</a>
    
    <a href="http://www.kikt.top/tags/ffmpeg/">ffmpeg</a>
    
    <a href="http://www.kikt.top/tags/flexmark/">flexmark</a>
    
    <a href="http://www.kikt.top/tags/flutter/">flutter</a>
    
    <a href="http://www.kikt.top/tags/flutter-web/">flutter-web</a>
    
    <a href="http://www.kikt.top/tags/focus/">focus</a>
    
    <a href="http://www.kikt.top/tags/focusNode/">focusNode</a>
    
    <a href="http://www.kikt.top/tags/form/">form</a>
    
    <a href="http://www.kikt.top/tags/framework/">framework</a>
    
    <a href="http://www.kikt.top/tags/github/">github</a>
    
    <a href="http://www.kikt.top/tags/go/">go</a>
    
    <a href="http://www.kikt.top/tags/golang/">golang</a>
    
    <a href="http://www.kikt.top/tags/gradle/">gradle</a>
    
    <a href="http://www.kikt.top/tags/http/">http</a>
    
    <a href="http://www.kikt.top/tags/iOS/">iOS</a>
    
    <a href="http://www.kikt.top/tags/ide/">ide</a>
    
    <a href="http://www.kikt.top/tags/idea/">idea</a>
    
    <a href="http://www.kikt.top/tags/index/">index</a>
    
    <a href="http://www.kikt.top/tags/inside/">inside</a>
    
    <a href="http://www.kikt.top/tags/ios/">ios</a>
    
    <a href="http://www.kikt.top/tags/java/">java</a>
    
    <a href="http://www.kikt.top/tags/jenkins/">jenkins</a>
    
    <a href="http://www.kikt.top/tags/jetbrains/">jetbrains</a>
    
    <a href="http://www.kikt.top/tags/jsdelivr/">jsdelivr</a>
    
    <a href="http://www.kikt.top/tags/json/">json</a>
    
    <a href="http://www.kikt.top/tags/json_serializable/">json_serializable</a>
    
    <a href="http://www.kikt.top/tags/junit/">junit</a>
    
    <a href="http://www.kikt.top/tags/library/">library</a>
    
    <a href="http://www.kikt.top/tags/live-template/">live-template</a>
    
    <a href="http://www.kikt.top/tags/loadmore/">loadmore</a>
    
    <a href="http://www.kikt.top/tags/log/">log</a>
    
    <a href="http://www.kikt.top/tags/mac/">mac</a>
    
    <a href="http://www.kikt.top/tags/macos/">macos</a>
    
    <a href="http://www.kikt.top/tags/maven/">maven</a>
    
    <a href="http://www.kikt.top/tags/mysql/">mysql</a>
    
    <a href="http://www.kikt.top/tags/navigationbar/">navigationbar</a>
    
    <a href="http://www.kikt.top/tags/navigator/">navigator</a>
    
    <a href="http://www.kikt.top/tags/ndk/">ndk</a>
    
    <a href="http://www.kikt.top/tags/nginx/">nginx</a>
    
    <a href="http://www.kikt.top/tags/oc/">oc</a>
    
    <a href="http://www.kikt.top/tags/opencv/">opencv</a>
    
    <a href="http://www.kikt.top/tags/poi/">poi</a>
    
    <a href="http://www.kikt.top/tags/pub/">pub</a>
    
    <a href="http://www.kikt.top/tags/python/">python</a>
    
    <a href="http://www.kikt.top/tags/retrofit/">retrofit</a>
    
    <a href="http://www.kikt.top/tags/route/">route</a>
    
    <a href="http://www.kikt.top/tags/server/">server</a>
    
    <a href="http://www.kikt.top/tags/so/">so</a>
    
    <a href="http://www.kikt.top/tags/spp/">spp</a>
    
    <a href="http://www.kikt.top/tags/sprintboot/">sprintboot</a>
    
    <a href="http://www.kikt.top/tags/swift/">swift</a>
    
    <a href="http://www.kikt.top/tags/tap/">tap</a>
    
    <a href="http://www.kikt.top/tags/thymeleaf/">thymeleaf</a>
    
    <a href="http://www.kikt.top/tags/tips/">tips</a>
    
    <a href="http://www.kikt.top/tags/toast/">toast</a>
    
    <a href="http://www.kikt.top/tags/transition/">transition</a>
    
    <a href="http://www.kikt.top/tags/ui/">ui</a>
    
    <a href="http://www.kikt.top/tags/utf8/">utf8</a>
    
    <a href="http://www.kikt.top/tags/yield/">yield</a>
    
    <a href="http://www.kikt.top/tags/%E4%BA%8C%E8%BF%9B%E5%88%B6/">二进制</a>
    
    <a href="http://www.kikt.top/tags/%E4%BA%A4%E5%8F%89/">交叉</a>
    
    <a href="http://www.kikt.top/tags/%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91/">交叉编译</a>
    
    <a href="http://www.kikt.top/tags/%E4%BB%8B%E7%BB%8D/">介绍</a>
    
    <a href="http://www.kikt.top/tags/%E4%BB%A3%E7%A0%81%E8%A7%84%E8%8C%83/">代码规范</a>
    
    <a href="http://www.kikt.top/tags/%E5%86%B2%E7%AA%81/">冲突</a>
    
    <a href="http://www.kikt.top/tags/%E5%8A%A8%E6%80%81/">动态</a>
    
    <a href="http://www.kikt.top/tags/%E5%8F%91%E5%B8%83/">发布</a>
    
    <a href="http://www.kikt.top/tags/%E5%8F%AF%E6%89%A7%E8%A1%8C/">可执行</a>
    
    <a href="http://www.kikt.top/tags/%E5%9B%BE%E5%BA%8A/">图床</a>
    
    <a href="http://www.kikt.top/tags/%E5%9F%8E%E5%B8%82/">城市</a>
    
    <a href="http://www.kikt.top/tags/%E5%A4%A7%E6%96%87%E4%BB%B6/">大文件</a>
    
    <a href="http://www.kikt.top/tags/%E5%B7%A5%E5%85%B7/">工具</a>
    
    <a href="http://www.kikt.top/tags/%E5%B7%B2%E6%9C%89%E9%A1%B9%E7%9B%AE/">已有项目</a>
    
    <a href="http://www.kikt.top/tags/%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/">开发环境</a>
    
    <a href="http://www.kikt.top/tags/%E6%80%BB%E7%BB%93/">总结</a>
    
    <a href="http://www.kikt.top/tags/%E6%85%A2/">慢</a>
    
    <a href="http://www.kikt.top/tags/%E6%89%93%E5%8C%85/">打包</a>
    
    <a href="http://www.kikt.top/tags/%E6%89%AB%E7%A0%81/">扫码</a>
    
    <a href="http://www.kikt.top/tags/%E6%8F%92%E4%BB%B6/">插件</a>
    
    <a href="http://www.kikt.top/tags/%E6%96%87%E6%A1%A3/">文档</a>
    
    <a href="http://www.kikt.top/tags/%E6%A8%A1%E6%9D%BF/">模板</a>
    
    <a href="http://www.kikt.top/tags/%E6%B8%B2%E6%9F%93/">渲染</a>
    
    <a href="http://www.kikt.top/tags/%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/">源码解析</a>
    
    <a href="http://www.kikt.top/tags/%E7%81%B0%E5%BA%A6/">灰度</a>
    
    <a href="http://www.kikt.top/tags/%E7%82%B9%E5%87%BB/">点击</a>
    
    <a href="http://www.kikt.top/tags/%E7%84%A6%E7%82%B9/">焦点</a>
    
    <a href="http://www.kikt.top/tags/%E7%88%AC%E8%99%AB/">爬虫</a>
    
    <a href="http://www.kikt.top/tags/%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86/">状态管理</a>
    
    <a href="http://www.kikt.top/tags/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE/">百度地图</a>
    
    <a href="http://www.kikt.top/tags/%E7%BC%96%E7%A0%81/">编码</a>
    
    <a href="http://www.kikt.top/tags/%E7%BC%96%E7%A8%8B%E6%8A%80%E5%B7%A7/">编程技巧</a>
    
    <a href="http://www.kikt.top/tags/%E7%BC%96%E8%AF%91/">编译</a>
    
    <a href="http://www.kikt.top/tags/%E7%BF%BB%E8%AF%91/">翻译</a>
    
    <a href="http://www.kikt.top/tags/%E8%93%9D%E7%89%99/">蓝牙</a>
    
    <a href="http://www.kikt.top/tags/%E8%A1%A8%E5%8D%95/">表单</a>
    
    <a href="http://www.kikt.top/tags/%E8%B7%AF%E7%94%B1/">路由</a>
    
    <a href="http://www.kikt.top/tags/%E8%BF%87%E5%9C%BA%E5%8A%A8%E7%94%BB/">过场动画</a>
    
    <a href="http://www.kikt.top/tags/%E9%9A%90%E7%A7%81/">隐私</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="https://github.com/Caijinglong" title="我的Github">我的Github</a>
        </li>
        
        <li>
            <a target="_blank" href="https://flutter.dev" title="flutter 官网">flutter 官网</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="http://www.kikt.top/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
        </div>
    </div>
</div>
<footer id="footer">
    <div class="container">
        <div>
            <p>如果我的blog对您有帮助,而您愿意捐赠 😆, 可以用下面的二维码</p>
            <img style="width:5rem;" src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&resolveLfs=true&%24format=octetStream&api-version=5.0&path=%2F20190424141834.png"/>
            <img style="width:5rem; padding-left: 2rem;" 
            src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&resolveLfs=true&%24format=octetStream&api-version=5.0&path=%2F20190424141931.png"/>
            <img style="width:5rem; padding-left: 2rem;" 
            src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&resolveLfs=true&%24format=octetStream&api-version=5.0&path=%2F20190424142013.png"/>
        </div>
        &copy; 2018 <a href="http://www.kikt.top">caijinglong的博客 By caijinglong</a>.
        Powered by <a rel="nofollow noreferer noopener" href="https://gohugo.io" target="_blank">Hugo</a>.
        <a href="http://www.flysnow.org/" target="_blank">Theme</a> based on <a href="https://github.com/rujews/maupassant-hugo" target="_blank">maupassant</a>.<br/>
        本站所有内容基于<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" style="color:coral">CC4.0</a>协议发布,需要转载必须署名
        <br/>
        如果有问题可以<a href="mailto:cjl_spy@163.com">email联系我</a>
        <br/>
        京ICP备18038473号-1
        
    </div>
</footer>


    <script type="text/javascript" src="/js/prism.js" async="true"></script>
    <script type="text/javascript">
    
    (function(){
        $("pre code").parent().addClass("line-numbers")
    }())

    window.MathJax = {
        tex2jax: {
            inlineMath: [ ['$','$'] ],
            processEscapes: true
        }
    };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src="/js/totop.js?v=0.0.0" async=""></script>



<script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




</body>
</html>
